﻿package net.area80.serverside.parser
{
	import net.area80.serverside.datatype.TopScoreData;
	import net.area80.serverside.datatype.UserInfo;
	
	/**
	* AdapterParser
	* Parser Function for Incoming XML from serverside script, related to Adapter format.
	* @author Wissarut Pimanmassuriya
	*/
	public class AdapterParser 
	{
		public static function topscoreParser (dataNode:XML):Array {
			
				var scoreList:Array = new Array();
				
				for each (var scoreXML:XML in dataNode.score) {
						var topData:TopScoreData = new TopScoreData();
						topData.name = scoreXML.@name;
						topData.lastname = scoreXML.@lastname;
						topData.rank = scoreXML.@rank;
						topData.score = scoreXML.@score;
						topData.extras = scoreXML.@extras;
						scoreList.push(topData);
				}
	
				return scoreList;
		}
		public static function userInfoParser (dataNode:XML):UserInfo {
				var userInfo:UserInfo = new UserInfo();
				
				userInfo.firstName = dataNode.sFirstName;
				userInfo.lastName = dataNode.sLastName;
				userInfo.email = dataNode.sEmail;
				userInfo.bestScore = dataNode.iBestScore;
				userInfo.rank = dataNode.iRank;
				userInfo.totalRank = dataNode.iTotalRank;
				userInfo.mobile = dataNode.sMobile;
				userInfo.extras = dataNode.sExtras;
				
				return userInfo;
		}
	}
	
}